package com.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

    public static int getApartDay(String startTime, String endTime){

        String startDayStr = startTime.substring(0, startTime.indexOf(' '));
        String endDayStr = endTime.substring(0, endTime.indexOf(' '));

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

        try{
            Date startDay = dateFormat.parse(startDayStr);
            Date endDay = dateFormat.parse(endDayStr);

            Date nextDay = startDay;
            int apartDay = 0;
            while(nextDay.before(endDay)) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(startDay);
                calendar.add(Calendar.DATE, 1);
                startDay = calendar.getTime();
                nextDay = startDay;
                apartDay++;
            }
            return  apartDay;
        }

        catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static String getCurrentTime(){
        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance();
        String dateString = dateFormat.format(date);

        return dateString;
    }
    
}
